﻿using System;
using ManpowerOrg.Bean;
using ManpowerOrg.Data;

namespace ManpowerOrg.Presentation_Control
{
	public partial class Login : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (ReferenceEquals(Session["Ticket"], "UnAuthen"))
			{
				lbStatus.Text = "Please Sign in first!";
				lbStatus.Visible = true;
			}
		}
		protected void BtnLogin_Click(object sender, EventArgs e)
		{
			var username = tbUsername.Text;
			var password = tbPassword.Text;

			SignIn(username, password);
		}
		private void SignIn(string user, string pwd)
		{
			var authen = new Authentication() { Username = user,Password = pwd};
			var authenData = new MPMAuthenticationData();
			var isAuthen = authenData.Authenticate(authen);
			if (isAuthen != null)
			{
				Session["Ticket"] = isAuthen.Ticket;
				Response.Redirect("MPMRequest.aspx");
			}
			else
			{
				lbStatus.Text = "Invalid username or password!";
				lbStatus.Visible = true;
			}
		}
	}
}